//
//  ShopCarHomeViewController.m
//  PrintPort
//
//  Created by 华谕 on 2017/11/11.
//  Copyright © 2017年 HUAYU. All rights reserved.
//

#import "ShopCarHomeViewController.h"
#import "OrderModel.h"
#import "GoodsModel.h"
#import "SizeListModel.h"
#import "SizeDetailModel.h"
#import "ImagelistModel.h"
#import "SelectedSpecModel.h"
#import "JSBadgeView.h"
#import "SoureOrderViewController.h"
#import "LookParameterViewController.h"

static NSString *cellPath = @"shopCarCell";
static NSString *ggCellPath = @"ggCell";
@interface ShopCarHomeViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>
{
    UIScrollView *titScrollview;
    UIView *bottonLine;
    UILabel *tongjiLab;
    UILabel *pricelab;
    UIView *classificationView;
    UIView *specificationsView;
    UIView *closeNumView;
    UITextField *numTextfield;
    CGFloat classHeight;
    UIButton *lookBtn;
    UILabel *integralLab;

}
@property (nonatomic, strong)UITableView *tableview;
@property (nonatomic, strong)UITableView *ggTableview;
@property (nonatomic, strong)NSArray *typeGgAry;
@property (nonatomic, strong)NSMutableArray *shopAry;
@property (nonatomic, assign)NSInteger page;
@property (nonatomic, strong)UIView *settleView;
@property (nonatomic, strong)UIButton *allCloseBtn;
@property (nonatomic, strong)UILabel *totalPriceLab;
@property (nonatomic, strong)UIView *closeGgView;
@property (nonatomic, strong)NSMutableDictionary *closeGoodsDic;
@property (nonatomic, assign)NSInteger indexrow;
@property (nonatomic, strong)NSMutableDictionary *priceDic;
@property (nonatomic, strong)NSMutableDictionary *integDic;
@property (nonatomic, assign)NSInteger allNumber;
@property (nonatomic, strong)GoodsModel *model;
@property (nonatomic, strong)OrderModel *ordModel;
@property (nonatomic, strong)NSMutableArray *selectArray;
@property (nonatomic, strong)NSMutableArray *selectOrderArray;
@property (nonatomic, strong)UIImageView *emptyImgview;
@property (nonatomic, strong)UILabel *tostLabel;

@property (nonatomic, assign)NSInteger classType;
@property (nonatomic, assign)NSInteger speciType;
@property (nonatomic, strong)NSString *classID;
@property (nonatomic, strong)NSString *speciID;
@property (nonatomic, strong)NSString *csID;
@property (nonatomic, assign)BOOL isClose;
@property (nonatomic, assign)BOOL isProbject;

@end

@implementation ShopCarHomeViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jianpanhuishou:) name:UIKeyboardWillHideNotification object:nil];
    [self requestShoppingCartList];
    
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    _page = 0;
    _closeGoodsDic = [NSMutableDictionary dictionaryWithCapacity:0];
    _priceDic = [NSMutableDictionary dictionaryWithCapacity:0];
    _integDic = [NSMutableDictionary dictionaryWithCapacity:0];
    _indexrow = 0;
    _allNumber = 0;
    _csID = @"";
    _shopAry = [NSMutableArray arrayWithCapacity:0];
    _selectArray = [NSMutableArray arrayWithCapacity:0];
    _selectOrderArray = [NSMutableArray arrayWithCapacity:0];
    [self creatUI];
    
}

- (void)creatUI
{
    self.view.backgroundColor = BacksColor;
    self.navigationItem.title = @"购物车";
    self.navigationController.navigationBar.translucent = NO;
    UIImage *searchBtnImage = [[UIImage imageNamed:@"lajit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:searchBtnImage style:UIBarButtonItemStyleDone target:self action:@selector(delectedCar)];
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-TABBAR_HEIGHT-STA_NAV_HEIGHT-50*displaywidth-SCREER_HeiX) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableview.backgroundColor = BacksColor;
    _tableview.tag = 11;
    [self.view addSubview:_tableview];
    self.tableview.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewHeaderData)];
    self.tableview.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreFootData)];
    self.tableview.mj_footer.automaticallyHidden = YES;
    self.tableview.estimatedRowHeight = 0;
    self.tableview.estimatedSectionHeaderHeight = 0;
    self.tableview.estimatedSectionFooterHeight = 0;
    self.settleView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-TABBAR_HEIGHT-STA_NAV_HEIGHT-50*displaywidth-SCREER_HeiX, SCREEN_WIDTH, 50*displaywidth)];
    _settleView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_settleView];
    
    self.emptyImgview = [ZCControl createImageViewWithFrame:CGRectMake(SCREEN_WIDTH/2-70*displaywidth, 120*displaywidth, 140*displaywidth, 140*displaywidth) ImageName:@"gouwuche222"];
    _emptyImgview.contentMode = UIViewContentModeScaleAspectFit;
    _emptyImgview.hidden = YES;
    [self.view addSubview:_emptyImgview];
    
    self.tostLabel = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 290*displaywidth, SCREEN_WIDTH-30*displaywidth, 30*displaywidth) Font:14.0 Text:@"购物车空空如也，赶紧去逛逛吧" Color:RGB(153, 153, 153)];
    _tostLabel.textAlignment = NSTextAlignmentCenter;
    _tostLabel.hidden = YES;
    [self.view addSubview:_tostLabel];
    
    self.allCloseBtn = [ZCControl createButtonWithFrame:CGRectMake(10*displaywidth, 5*displaywidth, 90*displaywidth, 40*displaywidth) ImageName:@"xuankuang" Target:self Action:@selector(allCloseAction:) Title:@" 全选" Font:14.0];
//    _allCloseBtn.selected = ;
    _allCloseBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    _allCloseBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    [_allCloseBtn setTitleColor:RGB(77, 77, 77) forState:UIControlStateNormal];
    [_settleView addSubview:_allCloseBtn];
    self.totalPriceLab = [ZCControl createLabelWithFrame:CGRectMake(110*displaywidth, 5*displaywidth, SCREEN_WIDTH-220*displaywidth, 40*displaywidth) Font:14.0 Text:@"合计：￥0.00元 + 0积分" Color:RGB(77, 77, 77)];
    _totalPriceLab.textAlignment = NSTextAlignmentRight;
    [_settleView addSubview:_totalPriceLab];
    UIButton *settlemBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-100*displaywidth, 0, 100*displaywidth, 50*displaywidth) ImageName:nil Target:self Action:@selector(settlemAction) Title:@"结算" Font:16.0];
    settlemBtn.backgroundColor = ThemeColor;
    [settlemBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_settleView addSubview:settlemBtn];
}

- (void)loadNewHeaderData
{
    _page = 0;
    [self requestShoppingCartList];
}

- (void)loadMoreFootData
{
    _page++;
    [self requestShoppingCartList];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView.tag == 11)
    {
        return _shopAry.count;
    }
    return _typeGgAry.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.tag == 11)
    {
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        if (!cell)
        {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellPath];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (_shopAry.count > 0)
        {
            OrderModel *model = _shopAry[indexPath.row];
            GoodsModel *goodsModel = model.goodsModel;
            
            NSString *imgStr = @"xuankuang";
            if (model.isXuanZh)
            {
                imgStr = @"yuand";
            }
            UIButton *closeBtn = [ZCControl createButtonWithFrame:CGRectMake(0, 30*displaywidth, 40*displaywidth, 40*displaywidth) ImageName:imgStr Target:self Action:@selector(closeShopAction:) Title:nil Font:12.0];
            closeBtn.tag = 100+indexPath.row;
            [cell.contentView addSubview:closeBtn];
            UIImageView *imgView = [ZCControl createImageViewWithFrame:CGRectMake(40*displaywidth, 10*displaywidth, 80*displaywidth, 80*displaywidth) ImageName:@""];
            if (goodsModel.productImgList.count > 0)
            {
                ImagelistModel *imgModel = goodsModel.productImgList[0];
                [imgView sd_setImageWithURL:[NSURL URLWithString:imgModel.imgUrl]];
            }
            [cell.contentView addSubview:imgView];
            UILabel *titlab = [ZCControl createLabelWithFrame:CGRectMake(140*displaywidth, 10*displaywidth, SCREEN_WIDTH-200*displaywidth, 25*displaywidth) Font:14.0 Text:[NSString stringWithFormat:@"%@",goodsModel.productName] Color:RGB(77, 77, 77)];
            titlab.lineBreakMode = NSLineBreakByTruncatingTail;
            [cell.contentView addSubview:titlab];
            NSArray *shopCarArray = model.shoppingCartDetailList;
            NSString *typeStr = @"分类：";
            for (SelectedSpecModel *selectModel in shopCarArray)
            {
                typeStr = [NSString stringWithFormat:@"%@%@,",typeStr,selectModel.productSizeDetailName];
            }
            typeStr = [typeStr substringToIndex:typeStr.length-1];
            UILabel *typeLab = [ZCControl createLabelWithFrame:CGRectMake(140*displaywidth, 35*displaywidth, SCREEN_WIDTH-200*displaywidth, 45*displaywidth) Font:12.0 Text:typeStr Color:RGB(179, 179, 179)];
            typeLab.lineBreakMode = UILineBreakModeTailTruncation;
            typeLab.adjustsFontSizeToFitWidth = NO;
            [cell.contentView addSubview:typeLab];
//            UILabel *moneyLab = [ZCControl createLabelWithFrame:CGRectMake(140*displaywidth, 80*displaywidth, SCREEN_WIDTH-220*displaywidth, 20*displaywidth) Font:12.0 Text:[NSString stringWithFormat:@" %@",model.moneyTol] Color:RGB(241, 90, 36)];
//            [cell.contentView addSubview:moneyLab];
            UILabel *moneyLab = [ZCControl createLabelWithFrame:CGRectMake(140*displaywidth, 80*displaywidth, SCREEN_WIDTH-220*displaywidth, 20*displaywidth) Font:12.0 Text:[NSString stringWithFormat:@"￥%@ +",model.moneyTol] Color:RGB(241, 90, 36)];
            CGRect abounds = [moneyLab.text boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-200*displaywidth, 20*displaywidth) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:NormalFontWithSize(12.0+fontScale)} context:nil];
            CGFloat width1 = abounds.size.width+20;
            moneyLab.frame = CGRectMake(140*displaywidth, 80*displaywidth, width1, 20*displaywidth);
            [cell.contentView addSubview:moneyLab];
            
            UILabel *integralLab = [ZCControl createLabelWithFrame:CGRectMake(width1+145*displaywidth, 82.5*displaywidth, 120*displaywidth, 15*displaywidth) Font:11.0 Text:[NSString stringWithFormat:@"%@积分",model.integralTol] Color:[UIColor whiteColor]];
            integralLab.textAlignment = NSTextAlignmentCenter;
            integralLab.layer.cornerRadius = 2;
            integralLab.layer.masksToBounds = YES;
            integralLab.backgroundColor = RGB(24, 159, 186);
            [cell.contentView addSubview:integralLab];
            CGRect bounds1 = [integralLab.text boundingRectWithSize:CGSizeMake(120*displaywidth, 20*displaywidth) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:NormalFontWithSize(11.0+fontScale)} context:nil];
            CGFloat width2 = bounds1.size.width+10;
            if (bounds1.size.width > 120*displaywidth)
            {
                width2 = 120*displaywidth;
            }
            integralLab.frame = CGRectMake(width1+145*displaywidth, 82.5*displaywidth, width2, 15*displaywidth);
            UIButton *editBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-50*displaywidth, 15*displaywidth, 20*displaywidth, 20*displaywidth) ImageName:@"bianji" Target:self Action:@selector(editBtnAction:) Title:nil Font:12.0];
            editBtn.tag = 1100+indexPath.row;
            [cell.contentView addSubview:editBtn];
            UILabel *numLab = [ZCControl createLabelWithFrame:CGRectMake(SCREEN_WIDTH-50*displaywidth, 80*displaywidth, 50*displaywidth, 20*displaywidth) Font:10.0 Text:[NSString stringWithFormat:@"x %@",model.numTol] Color:RGB(179, 179, 179)];
            [cell.contentView addSubview:numLab];
            if (model.isEdit)
            {
                editBtn.hidden = YES;
                numLab.hidden = YES;
                typeLab.hidden = YES;
                moneyLab.hidden = YES;
                integralLab.hidden = YES;
                UIButton *completeBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-50*displaywidth, 0, 50*displaywidth, 100*displaywidth) ImageName:nil Target:self Action:@selector(completeAction:) Title:@"完成" Font:16.0];
                completeBtn.tag = 2100+indexPath.row;
                completeBtn.backgroundColor = ThemeColor;
                [completeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                [cell.contentView addSubview:completeBtn];
                UIView *closeGGview = [[UIView alloc] initWithFrame:CGRectMake(140*displaywidth, 50*displaywidth, SCREEN_WIDTH-200*displaywidth, 40*displaywidth)];
                closeGGview.backgroundColor = [UIColor whiteColor];
                closeGGview.layer.cornerRadius = 2;
                closeGGview.layer.masksToBounds = YES;
                closeGGview.layer.borderColor = RGB(204, 204, 204).CGColor;
                closeGGview.layer.borderWidth = 1;
                [cell.contentView addSubview:closeGGview];
                UILabel *tostLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 0, SCREEN_WIDTH-240*displaywidth, 40*displaywidth) Font:12.0 Text:@"选择分类/规格" Color:RGB(179, 179, 179)];
                [closeGGview addSubview:tostLab];
                UIImageView *showImgView = [ZCControl createImageViewWithFrame:CGRectMake(SCREEN_WIDTH-220*displaywidth, 12.5*displaywidth, 15*displaywidth, 15*displaywidth) ImageName:@"xiahuaxuanze"];
                showImgView.contentMode = UIViewContentModeScaleAspectFit;
                [closeGGview addSubview:showImgView];
                UIButton *reloCloseBtn = [ZCControl createButtonWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-200*displaywidth, 40*displaywidth) ImageName:nil Target:self Action:@selector(reloClosAction:) Title:nil Font:12.0];
                reloCloseBtn.backgroundColor = [UIColor clearColor];
                reloCloseBtn.tag = 3100+indexPath.row;
                [closeGGview addSubview:reloCloseBtn];
                
            }
            UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 100*displaywidth, SCREEN_WIDTH, 10*displaywidth)];
            lineView.backgroundColor = BacksColor;
            [cell.contentView addSubview:lineView];
        }
        return cell;
    }
    else
    {
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        if (!cell)
        {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ggCellPath];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (_typeGgAry.count > 0)
        {
            SizeDetailModel *model = _typeGgAry[indexPath.row];
            UILabel *nameLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 5*displaywidth, 180*displaywidth, 25*displaywidth) Font:14.0 Text:model.productSizeDetailName Color:RGB(77, 77, 77)];
            [cell.contentView addSubview:nameLab];
            UILabel *priceLab = [ZCControl createLabelWithFrame:CGRectMake(17.5*displaywidth, 30*displaywidth, 180*displaywidth, 15*displaywidth) Font:11.0 Text:[NSString stringWithFormat:@"￥%@元 + %@积分",model.price,model.integral] Color:RGB(179, 179, 179)];
            [cell.contentView addSubview:priceLab];
            UILabel *kucunLab = [ZCControl createLabelWithFrame:CGRectMake(SCREEN_WIDTH-200*displaywidth, 5*displaywidth, 70*displaywidth, 40*displaywidth) Font:11.0 Text:[NSString stringWithFormat:@"库存：%@",model.productStock] Color:RGB(179, 179, 179)];
            kucunLab.textAlignment = NSTextAlignmentRight;
            [cell.contentView addSubview:kucunLab];
            UIView *numView = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-125*displaywidth, 10*displaywidth, 110*displaywidth, 30*displaywidth)];
            numView.backgroundColor = [UIColor whiteColor];
            numView.layer.cornerRadius = 2;
            numView.layer.masksToBounds = YES;
            numView.layer.borderColor = RGB(204, 204, 204).CGColor;
            numView.layer.borderWidth = 1;
            [cell.contentView addSubview:numView];
            UIView *line01 = [[UIView alloc] initWithFrame:CGRectMake(29*displaywidth, 0, 1*displaywidth, 30*displaywidth)];
            line01.backgroundColor = RGB(204, 204, 204);
            [numView addSubview:line01];
            UIView *line02 = [[UIView alloc] initWithFrame:CGRectMake(80*displaywidth, 0, 1*displaywidth, 30*displaywidth)];
            line02.backgroundColor = RGB(204, 204, 204);
            [numView addSubview:line02];
            UIButton *deleteBtn = [ZCControl createButtonWithFrame:CGRectMake(0, 0, 30*displaywidth, 30*displaywidth) ImageName:nil Target:self Action:@selector(deleteBtnAction:) Title:@"-" Font:16.0];
            deleteBtn.backgroundColor = [UIColor clearColor];
            [deleteBtn setTitleColor:RGB(179, 179, 179) forState:UIControlStateNormal];
            deleteBtn.tag = indexPath.row + 200;
            [numView addSubview:deleteBtn];
            UIButton *addBtn = [ZCControl createButtonWithFrame:CGRectMake(80*displaywidth, 0, 30*displaywidth, 30*displaywidth) ImageName:nil Target:self Action:@selector(addBtnAction:) Title:@"+" Font:16.0];
            addBtn.backgroundColor = [UIColor clearColor];
            [addBtn setTitleColor:RGB(179, 179, 179) forState:UIControlStateNormal];
            addBtn.tag = indexPath.row + 2200;
            [numView addSubview:addBtn];
            UITextField *textfield = [ZCControl createTextFieldWithFrame:CGRectMake(30*displaywidth, 0, 50*displaywidth, 30*displaywidth) placeholder:@"0" passWord:NO leftImageView:nil rightImageView:nil Font:13.0];
            [textfield setValue:RGB(77, 77, 77) forKeyPath:@"_placeholderLabel.textColor"];
            textfield.textColor = RGB(77, 77, 77);
            textfield.textAlignment = NSTextAlignmentCenter;
            textfield.delegate = self;
            textfield.tag = indexPath.row + 3000;
            textfield.keyboardType = UIKeyboardTypeNumberPad;
            [numView addSubview:textfield];
            if ([_closeGoodsDic.allKeys containsObject:model.productSizeId])
            {
                NSDictionary *dic = [_closeGoodsDic objectForKey:model.productSizeId];
                if ([dic.allKeys containsObject:model.ID])
                {
                    NSString *numStr = [dic objectForKey:model.ID];
                    textfield.text = numStr;
                }
                else
                {
                    textfield.text = @"0";
                }
            }
            else
            {
                textfield.text = @"0";

            }
        }
        UIView *lineview33 = [[UIView alloc] initWithFrame:CGRectMake(0, 49, SCREEN_WIDTH, 1*displaywidth)];
        lineview33.backgroundColor = LinesColor;
        [cell.contentView addSubview:lineview33];
        return cell;
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.tag == 11)
    {
        return 110*displaywidth;
    }
    else
    {
        return 50*displaywidth;
    }
}

//全选
- (void)allCloseAction:(UIButton *)btn
{
    btn.selected = !btn.selected;
    if (btn.selected)
    {
        [btn setImage:[UIImage imageNamed:@"yuand"] forState:UIControlStateNormal];
        for (OrderModel *model in _shopAry)
        {
            model.isXuanZh = YES;
        }
    }
    else
    {
        [btn setImage:[UIImage imageNamed:@"xuankuang"] forState:UIControlStateNormal];
        for (OrderModel *model in _shopAry)
        {
            model.isXuanZh = NO;
        }
    }
    
    [_tableview reloadData];
    [self getSelectedArray];
}

//删除
- (void)delectedCar
{
    [self getSelectedArray];
    if (_selectArray.count == 0)
    {
        [LTools showMBProgressWithText:@"请选择需要删除的商品" addToView:self.view];
        return;
    }
    WEAKSELF;
    UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"您将要删除选中的%ld件商品",_selectArray.count] message:@"" preferredStyle:UIAlertControllerStyleAlert];
    [alertVc addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    
    }]];
    [alertVc addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [weakSelf requestShoppingCartDelete];
    }]];
    [self presentViewController:alertVc animated:YES completion:nil];
    
}

//结算
- (void)settlemAction
{
    [self getSelectedArray];
    if (_selectOrderArray.count == 0)
    {
        [LTools showMBProgressWithText:@"请选择结算的商品" addToView:self.view];
        return;
    }
    SoureOrderViewController *vc = [[SoureOrderViewController alloc] init];
    vc.orderAry = _selectOrderArray;
    [self.navigationController pushViewController:vc animated:YES];
}

//选中
- (void)closeShopAction:(UIButton *)btn
{
    NSInteger index = btn.tag-100;
    OrderModel *model = _shopAry[index];
    model.isXuanZh = !model.isXuanZh;
    [_tableview reloadData];
    [self getSelectedArray];
    
}

//编辑
- (void)editBtnAction:(UIButton *)btn
{
    NSInteger index = btn.tag-1100;
    OrderModel *model = _shopAry[index];
    model.isEdit = YES;
    [_tableview reloadData];
}

//完成编辑
- (void)completeAction:(UIButton *)btn
{
    NSInteger index = btn.tag-2100;
    OrderModel *model = _shopAry[index];
    model.isEdit = NO;
    [_tableview reloadData];
}

//选择规格分类
- (void)reloClosAction:(UIButton *)btn
{
    NSInteger index = btn.tag-3100;
    OrderModel *model = _shopAry[index];
    GoodsModel *ggModel = model.goodsModel;
    [self.closeGgView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    [self.closeGgView removeFromSuperview];
    self.closeGgView = nil;
    _isClose = YES;
    _model = ggModel;
    _ordModel = model;
    [self getAllGgPrice];
    NSArray *selectAry = model.shoppingCartDetailList;
    [_closeGoodsDic removeAllObjects];
    for (SelectedSpecModel *seleModel in selectAry)
    {
        if ([_closeGoodsDic.allKeys containsObject:seleModel.productSizeId])
        {
            NSDictionary *dic = [_closeGoodsDic objectForKey:seleModel.productSizeId];
            NSMutableDictionary *newDic = [NSMutableDictionary dictionaryWithCapacity:0];
            [newDic addEntriesFromDictionary:dic];
            [newDic setObject:seleModel.num forKey:seleModel.productSizeDetailId];
            
            [_closeGoodsDic setObject:newDic forKey:seleModel.productSizeId];
        }
        else
        {
            NSMutableDictionary *newDic = [NSMutableDictionary dictionaryWithCapacity:0];
            [newDic setObject:seleModel.num forKey:seleModel.productSizeDetailId];
            [_closeGoodsDic setObject:newDic forKey:seleModel.productSizeId];
            
        }
        
        
    }
    NSInteger area = [ggModel.area integerValue];
    if (area == 2)
    {
        [self creatCloseGgView:ggModel];
    }
    else if(area == 3 || area == 1)
    {
        if (area == 1)
        {
            _isProbject = YES;
        }
        else
        {
            _isProbject = NO;
        }
        [self creatNewCloseGgView];
    }
    
}

- (void)creatNewCloseGgView
{
    if (!self.closeGgView)
    {
        self.closeGgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        _closeGgView.backgroundColor = RGBA(0, 0, 0, 0.5);
        [sharedDelegate.window addSubview:_closeGgView];
        
        UIView *whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-315*displaywidth-SCREER_HeiX, SCREEN_HEIGHT, 315*displaywidth+SCREER_HeiX)];
        whiteView.backgroundColor = [UIColor whiteColor];
        [_closeGgView addSubview:whiteView];
        UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];
        tap1.cancelsTouchesInView = NO;
        [whiteView addGestureRecognizer:tap1];
        UIImageView *imgView = [ZCControl createImageViewWithFrame:CGRectMake(15*displaywidth, 15*displaywidth, 70*displaywidth, 70*displaywidth) ImageName:@""];
        if (_model.productImgList.count > 0)
        {
            ImagelistModel *imgModel = _model.productImgList[0];
            [imgView sd_setImageWithURL:[NSURL URLWithString:imgModel.imgUrl]];
        }
        [whiteView addSubview:imgView];
        UILabel *titlab = [ZCControl createLabelWithFrame:CGRectMake(100*displaywidth, 10*displaywidth, SCREEN_WIDTH-145*displaywidth, 30*displaywidth) Font:14.0 Text:[NSString stringWithFormat:@"%@",_model.productName] Color:RGB(77, 77, 77)];
        titlab.lineBreakMode = NSLineBreakByTruncatingTail;
        [whiteView addSubview:titlab];
        UIButton *backGGBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-30*displaywidth, 10*displaywidth, 20*displaywidth, 20*displaywidth) ImageName:@"guanbi" Target:self Action:@selector(backGGAction) Title:nil Font:12.0];
        backGGBtn.backgroundColor = [UIColor clearColor];
        [whiteView addSubview:backGGBtn];
//        pricelab = [ZCControl createLabelWithFrame:CGRectMake(100*displaywidth, 55*displaywidth, SCREEN_WIDTH-145*displaywidth, 20*displaywidth) Font:14.0 Text:_model.priceDescribe Color:RGB(241, 90, 36)];
//        [whiteView addSubview:pricelab];
        pricelab = [ZCControl createLabelWithFrame:CGRectMake(100*displaywidth, 50*displaywidth, SCREEN_WIDTH-145*displaywidth, 20*displaywidth) Font:14.0 Text:[_model.priceDescribe stringByAppendingString:@" +"] Color:RGB(241, 90, 36)];
        [whiteView addSubview:pricelab];
        integralLab = [ZCControl createLabelWithFrame:CGRectMake(100*displaywidth, 70*displaywidth, 120*displaywidth, 15*displaywidth) Font:11.0 Text:[NSString stringWithFormat:@"%@积分",_model.integral] Color:[UIColor whiteColor]];
        integralLab.textAlignment = NSTextAlignmentCenter;
        integralLab.layer.cornerRadius = 2;
        integralLab.layer.masksToBounds = YES;
        integralLab.backgroundColor = RGB(24, 159, 186);
        [whiteView addSubview:integralLab];
        CGRect bounds1 = [integralLab.text boundingRectWithSize:CGSizeMake(120*displaywidth, 15*displaywidth) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:NormalFontWithSize(11.0+fontScale)} context:nil];
        CGFloat width1 = bounds1.size.width+10;
        if (bounds1.size.width > 120*displaywidth)
        {
            width1 = 120*displaywidth;
        }
        integralLab.frame = CGRectMake(100*displaywidth, 70*displaywidth, width1, 15*displaywidth);
        lookBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-100*displaywidth, 67.5*displaywidth, 100*displaywidth, 20*displaywidth) ImageName:nil Target:self Action:@selector(lookAction) Title:@"查看参数>>" Font:12.0];
        [lookBtn setTitleColor:ThemeColor forState:UIControlStateNormal];
        lookBtn.hidden = !_isProbject;
        [whiteView addSubview:lookBtn];
        
        UIView *lineview = [[UIView alloc] initWithFrame:CGRectMake(0, 99*displaywidth, SCREEN_WIDTH, 1*displaywidth)];
        lineview.backgroundColor = LinesColor;
        [whiteView addSubview:lineview];
        
        titScrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 100*displaywidth, SCREEN_WIDTH, 170*displaywidth)];
        titScrollview.backgroundColor = [UIColor whiteColor];
        titScrollview.delegate = self;
        titScrollview.contentOffset = CGPointMake(0, 0);
        titScrollview.pagingEnabled = NO;
        titScrollview.bounces = NO;
        titScrollview.showsHorizontalScrollIndicator = YES;
        [whiteView addSubview:titScrollview];
        classificationView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 300*displaywidth)];
        classificationView.backgroundColor = [UIColor whiteColor];
        [titScrollview addSubview:classificationView];
        CGFloat h2 = 35*displaywidth;
        CGFloat h22 = 35*displaywidth;
        if (_model.productSizeList.count > 0)
        {
            NSArray *producListAry = _model.productSizeList;
            UILabel *typeLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 0, 100*displaywidth, 29*displaywidth) Font:14.0 Text:@"类型" Color:BlaTiColor];
            [classificationView addSubview:typeLab];
            CGFloat width = SCREEN_WIDTH-30*displaywidth;
            CGFloat w2 = 0;
            for (int i = 0; i < producListAry.count; i++)
            {
                SizeListModel *sizeModel = producListAry[i];
                NSString *typename = sizeModel.productSizeName;
                UIButton *tasteBtn = [ZCControl createButtonWithFrame:CGRectMake(15*displaywidth+i*75*displaywidth, h2, 60*displaywidth, 25*displaywidth) ImageName:nil Target:self Action:@selector(tasteBtnAction:) Title:typename Font:12.0];
                tasteBtn.tag = 500+i;
                NSDictionary *attributes = @{NSFontAttributeName:NormalFontWithSize(12.0+fontScale)};
                CGFloat length = [typename boundingRectWithSize:CGSizeMake(width-20*displaywidth, 25*displaywidth) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size.width;
                tasteBtn.frame = CGRectMake(15*displaywidth + w2, h2, length + 15*displaywidth , 25*displaywidth);
                if (length > width-20*displaywidth)
                {
                    length = width-20*displaywidth;
                }
                if(15*displaywidth + w2 + length + 15*displaywidth > width){
                    w2 = 0; //换行时将w置为0
                    h2 = h2 + tasteBtn.frame.size.height + 10*displaywidth;//距离父视图也变化
                    tasteBtn.frame = CGRectMake(15*displaywidth + w2, h2, length + 15*displaywidth, 25*displaywidth);//重设button的frame
                }
                w2 = tasteBtn.frame.size.width + tasteBtn.frame.origin.x;
                UIColor *bordercolor2 = RGB(222, 222, 222);
                UIColor *titcolor2 = RGB(77, 77, 77);
                if ([_closeGoodsDic.allKeys containsObject:s_str(sizeModel.ID)])
                {
                    _classID = s_str(sizeModel.ID);
                    bordercolor2 = ThemeColor;
                    _classType = i;
                    titcolor2 = [UIColor whiteColor];
                }
                [tasteBtn setTitleColor:titcolor2 forState:UIControlStateNormal];
                tasteBtn.layer.cornerRadius = 12.5*displaywidth;
                tasteBtn.layer.masksToBounds = YES;
                tasteBtn.backgroundColor = bordercolor2;
                [classificationView addSubview:tasteBtn];
                
            }
            h2+=45*displaywidth;
            classHeight = h2;
            classificationView.frame = CGRectMake(0, 0, SCREEN_WIDTH, h2);
            titScrollview.contentSize = CGSizeMake(SCREEN_WIDTH, h2+45*displaywidth);
            specificationsView = [[UIView alloc] initWithFrame:CGRectMake(0, h2, SCREEN_WIDTH, 300*displaywidth)];
            specificationsView.backgroundColor = [UIColor whiteColor];
            [titScrollview addSubview:specificationsView];
            SizeListModel *sizeModel = producListAry[_classType];
            NSArray *SizeDetailAry = sizeModel.productSizeDetailList;
            if (SizeDetailAry.count > 0)
            {
                [self reloadSpeciView:SizeDetailAry];
            }
            h22 = specificationsView.frame.size.height;
            closeNumView = [[UIView alloc] initWithFrame:CGRectMake(0, h22+h2, SCREEN_WIDTH, 45*displaywidth)];
            closeNumView.backgroundColor = [UIColor whiteColor];
            [titScrollview addSubview:closeNumView];
            UIView *lineNView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 1*displaywidth)];
            lineNView.backgroundColor = LinesColor;
            [closeNumView addSubview:lineNView];
            UILabel *buyNumLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 1*displaywidth, SCREEN_WIDTH-145*displaywidth, 44*displaywidth) Font:14.0 Text:@"购买数量" Color:BlaTiColor];
            [closeNumView addSubview:buyNumLab];
            UIView *numView = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-140*displaywidth, 8*displaywidth, 110*displaywidth, 30*displaywidth)];
            numView.backgroundColor = [UIColor whiteColor];
            numView.layer.cornerRadius = 2;
            numView.layer.masksToBounds = YES;
            numView.layer.borderColor = RGB(204, 204, 204).CGColor;
            numView.layer.borderWidth = 1;
            [closeNumView addSubview:numView];
            UIView *line01 = [[UIView alloc] initWithFrame:CGRectMake(29*displaywidth, 0, 1*displaywidth, 30*displaywidth)];
            line01.backgroundColor = RGB(204, 204, 204);
            [numView addSubview:line01];
            UIView *line02 = [[UIView alloc] initWithFrame:CGRectMake(80*displaywidth, 0, 1*displaywidth, 30*displaywidth)];
            line02.backgroundColor = RGB(204, 204, 204);
            [numView addSubview:line02];
            UIButton *deleteBtn = [ZCControl createButtonWithFrame:CGRectMake(0, 0, 30*displaywidth, 30*displaywidth) ImageName:nil Target:self Action:@selector(deleteBtnActionONE:) Title:@"-" Font:16.0];
            deleteBtn.backgroundColor = [UIColor clearColor];
            [deleteBtn setTitleColor:RGB(179, 179, 179) forState:UIControlStateNormal];
            [numView addSubview:deleteBtn];
            UIButton *addBtn = [ZCControl createButtonWithFrame:CGRectMake(80*displaywidth, 0, 30*displaywidth, 30*displaywidth) ImageName:nil Target:self Action:@selector(addBtnActionONE:) Title:@"+" Font:16.0];
            addBtn.backgroundColor = [UIColor clearColor];
            [addBtn setTitleColor:RGB(179, 179, 179) forState:UIControlStateNormal];
            [numView addSubview:addBtn];
            UITextField *textfield = [ZCControl createTextFieldWithFrame:CGRectMake(30*displaywidth, 0, 50*displaywidth, 30*displaywidth) placeholder:@"" passWord:NO leftImageView:nil rightImageView:nil Font:13.0];
            [textfield setValue:RGB(77, 77, 77) forKeyPath:@"_placeholderLabel.textColor"];
            textfield.textColor = RGB(77, 77, 77);
            textfield.text = @"0";
            textfield.textAlignment = NSTextAlignmentCenter;
            textfield.delegate = self;
            textfield.keyboardType = UIKeyboardTypeNumberPad;
            [numView addSubview:textfield];
            numTextfield = textfield;
        }
        UIView *line33 = [[UIView alloc] initWithFrame:CGRectMake(0, 270*displaywidth, SCREEN_WIDTH, 1*displaywidth)];
        line33.backgroundColor = LinesColor;
        [whiteView addSubview:line33];
        tongjiLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 275*displaywidth, SCREEN_WIDTH-135*displaywidth, 35*displaywidth) Font:14.0 Text:@"共 0 件商品  合计：￥0.00元 + 0积分" Color:RGB(77, 77, 77)];
        tongjiLab.textAlignment = NSTextAlignmentRight;
        NSMutableAttributedString *noteString = [[NSMutableAttributedString alloc] initWithString:tongjiLab.text];
        NSRange stringRange = NSMakeRange(2, 1);
        NSRange stringRange22 = NSMakeRange(tongjiLab.text.length-10, 5);
        NSRange stringRange33 = NSMakeRange(tongjiLab.text.length-3, 1);
        [noteString addAttribute:NSForegroundColorAttributeName value:RGB(241, 90, 36) range:stringRange];
        [noteString addAttribute:NSForegroundColorAttributeName value:RGB(241, 90, 36) range:stringRange22];
        [noteString addAttribute:NSForegroundColorAttributeName value:RGB(241, 90, 36) range:stringRange33];
        [tongjiLab setAttributedText:noteString];
        [whiteView addSubview:tongjiLab];
        UIButton *soureBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-100*displaywidth, 270*displaywidth, 100*displaywidth, 45*displaywidth) ImageName:nil Target:self Action:@selector(soureAction) Title:@"确定" Font:16.0];
        soureBtn.backgroundColor = ThemeColor;
        [soureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [whiteView addSubview:soureBtn];
    }
    NSDictionary *ggDic = @{};
    if ([_closeGoodsDic.allKeys containsObject:_classID])
    {
        ggDic = [_closeGoodsDic objectForKey:_classID];
        if ([ggDic.allKeys containsObject:_speciID])
        {
            NSString *numString = [ggDic objectForKey:_speciID];
            numTextfield.text = numString;
        }
    }
    [self tongjiNewNumberAndMoney];
    _closeGgView.hidden = NO;
}

- (void)lookAction
{
    _closeGgView.hidden = YES;
    if ([_csID isEqualToString:@"0"])
    {
        [LTools showMBProgressWithText:@"请选择gui'ge" addToView:self.view];
        return;
    }
    LookParameterViewController *vc = [[LookParameterViewController alloc] init];
    vc.parmerID = _csID;
    [self.navigationController pushViewController:vc animated:YES];
}

//减少数量
- (void)deleteBtnActionONE:(UIButton *)btn
{
    [_closeGgView endEditing:YES];
    [self.view endEditing:YES];
    if (!_isClose)
    {
        [LTools showMBProgressWithText:@"请选择规格" addToView:self.view];
        return;
    }
    NSInteger num = [numTextfield.text integerValue];
    if (num < 2)
    {
        return;
    }
    numTextfield.text = s_Integer(num-1);
    [self tongjiNewNumberAndMoney];
    
}

//添加数量
- (void)addBtnActionONE:(UIButton *)btn
{
    [_closeGgView endEditing:YES];
    [self.view endEditing:YES];
    if (!_isClose)
    {
        [LTools showMBProgressWithText:@"请选择规格" addToView:sharedDelegate.window];
        return;
    }
    NSInteger num = [numTextfield.text integerValue];
    numTextfield.text = s_Integer(num+1);
    [self tongjiNewNumberAndMoney];
}


//选择类型
- (void)tasteBtnAction:(UIButton *)btn
{
    NSInteger index = btn.tag-500;
    for (id v in classificationView.subviews)
    {
        if ([v isKindOfClass:[UIButton class]])
        {
            UIButton *button = (UIButton *)v;
            [button setTitleColor:RGB(77, 77, 77) forState:UIControlStateNormal];
            button.backgroundColor = RGB(222, 222, 222);
        }
    }
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn.backgroundColor = ThemeColor;
    if (index == _classType)
    {
        return;
    }
    _classType = index;
    _speciType = 0;
    _isClose = NO;
    numTextfield.text = @"0";
    NSArray *producListAry = _model.productSizeList;
    SizeListModel *sizeModel = producListAry[index];
    NSArray *SizeDetailAry = sizeModel.productSizeDetailList;
    for (id subView in specificationsView.subviews)
    {
        [subView removeFromSuperview];
    }
    [self reloadSpeciView:SizeDetailAry];
    [self tongjiNewNumberAndMoney];
}

- (void)reloadSpeciView:(NSArray *)SizeDetailAry
{
    UILabel *typeBLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 0, 100*displaywidth, 29*displaywidth) Font:14.0 Text:@"规格" Color:BlaTiColor];
    [specificationsView addSubview:typeBLab];
    CGFloat width = SCREEN_WIDTH-30*displaywidth;
    CGFloat w22 = 0;
    CGFloat h22 = 35*displaywidth;
    NSDictionary *ggDic = @{};
    if ([_closeGoodsDic.allKeys containsObject:_classID])
    {
        ggDic = [_closeGoodsDic objectForKey:_classID];
    }
    for (int i = 0; i < SizeDetailAry.count; i++)
    {
        SizeDetailModel *detailmodel = SizeDetailAry[i];
        NSString *typename = detailmodel.productSizeDetailName;
        
        UIButton *speciBtn = [ZCControl createButtonWithFrame:CGRectMake(15*displaywidth+i*75*displaywidth, h22, 60*displaywidth, 25*displaywidth) ImageName:nil Target:self Action:@selector(speciBtnAction:) Title:typename Font:12.0];
        speciBtn.tag = 1000+i;
        NSDictionary *attributes = @{NSFontAttributeName:NormalFontWithSize(12.0+fontScale)};
        CGFloat length = [typename boundingRectWithSize:CGSizeMake(width-20*displaywidth, 25*displaywidth) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size.width;
        speciBtn.frame = CGRectMake(15*displaywidth + w22, h22, length + 15*displaywidth , 25*displaywidth);
        if (length > width-20*displaywidth)
        {
            length = width-20*displaywidth;
        }
        if(15*displaywidth + w22 + length + 15*displaywidth > width){
            w22 = 0; //换行时将w置为0
            h22 = h22 + speciBtn.frame.size.height + 10*displaywidth;//距离父视图也变化
            speciBtn.frame = CGRectMake(15*displaywidth + w22, h22, length + 15*displaywidth, 25*displaywidth);//重设button的frame
        }
        w22 = speciBtn.frame.size.width + speciBtn.frame.origin.x;
        UIColor *bordercolor2 = RGB(222, 222, 222);
        UIColor *titcolor2 = RGB(77, 77, 77);
        if ([ggDic.allKeys containsObject:s_str(detailmodel.ID)])
        {
            _speciID = s_str(detailmodel.ID);
            _speciType = i;
            _csID = s_str(detailmodel.ID);
            bordercolor2 = ThemeColor;
            titcolor2 = [UIColor whiteColor];
        }
        [speciBtn setTitleColor:titcolor2 forState:UIControlStateNormal];
        speciBtn.layer.cornerRadius = 12.5*displaywidth;
        speciBtn.layer.masksToBounds = YES;
        speciBtn.backgroundColor = bordercolor2;
        [specificationsView addSubview:speciBtn];
        
    }
    h22 += 45*displaywidth;
    specificationsView.frame = CGRectMake(0, classHeight, SCREEN_WIDTH, h22);
    titScrollview.contentSize = CGSizeMake(SCREEN_WIDTH, classHeight+h22+45*displaywidth);
    closeNumView.frame = CGRectMake(0, classHeight+h22, SCREEN_WIDTH, 45*displaywidth);
}

//选择规格
- (void)speciBtnAction:(UIButton *)btn
{
    NSInteger index = btn.tag-1000;
    for (id v in specificationsView.subviews)
    {
        if ([v isKindOfClass:[UIButton class]])
        {
            UIButton *button = (UIButton *)v;
            [button setTitleColor:RGB(77, 77, 77) forState:UIControlStateNormal];
            button.backgroundColor = RGB(222, 222, 222);
        }
    }
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn.backgroundColor = ThemeColor;
    if (!_isClose)
    {
        UIButton *classBtn = (UIButton *)[classificationView viewWithTag:500+_classType];
        [classBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        classBtn.backgroundColor = ThemeColor;
    }
    if (index != _speciType)
    {
        numTextfield.text = @"1";
    }
    if ([numTextfield.text isEqualToString:@"0"] && index == 0)
    {
        numTextfield.text = @"1";
    }
    
    _speciType = index;
    _isClose = YES;
    [self tongjiNewNumberAndMoney];
}







- (void)creatCloseGgView:(GoodsModel *)goodsModel
{
    if (!self.closeGgView)
    {
        self.closeGgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        _closeGgView.backgroundColor = RGBA(0, 0, 0, 0.5);
        [sharedDelegate.window addSubview:_closeGgView];
        
        UIView *whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-480*displaywidth-SCREER_HeiX, SCREEN_HEIGHT, 480*displaywidth)];
        whiteView.backgroundColor = [UIColor whiteColor];
        [_closeGgView addSubview:whiteView];
        UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];
        tap1.cancelsTouchesInView = NO;
        [whiteView addGestureRecognizer:tap1];
        UIImageView *imgView = [ZCControl createImageViewWithFrame:CGRectMake(25*displaywidth, 15*displaywidth, 70*displaywidth, 70*displaywidth) ImageName:@""];
        if (goodsModel.productImgList.count > 0)
        {
            ImagelistModel *imgModel = goodsModel.productImgList[0];
            [imgView sd_setImageWithURL:[NSURL URLWithString:imgModel.imgUrl]];
        }
        [whiteView addSubview:imgView];
        UILabel *titlab = [ZCControl createLabelWithFrame:CGRectMake(110*displaywidth, 10*displaywidth, SCREEN_WIDTH-145*displaywidth, 30*displaywidth) Font:14.0 Text:[NSString stringWithFormat:@"%@（%@）",goodsModel.productName,goodsModel.unit] Color:RGB(77, 77, 77)];
        titlab.lineBreakMode = NSLineBreakByTruncatingTail;
        [whiteView addSubview:titlab];
        UIButton *backGGBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-30*displaywidth, 10*displaywidth, 20*displaywidth, 20*displaywidth) ImageName:@"guanbi" Target:self Action:@selector(backGGAction) Title:nil Font:12.0];
        backGGBtn.backgroundColor = [UIColor clearColor];
        [whiteView addSubview:backGGBtn];
    
        UILabel *pricelab = [ZCControl createLabelWithFrame:CGRectMake(110*displaywidth, 45*displaywidth, SCREEN_WIDTH-145*displaywidth, 20*displaywidth) Font:14.0 Text:[_model.priceDescribe stringByAppendingString:@" +"] Color:RGB(241, 90, 36)];
        [whiteView addSubview:pricelab];
        UILabel *integralLab = [ZCControl createLabelWithFrame:CGRectMake(110*displaywidth, 65*displaywidth, 120*displaywidth, 15*displaywidth) Font:11.0 Text:[NSString stringWithFormat:@"%@积分",_model.integral] Color:[UIColor whiteColor]];
        integralLab.textAlignment = NSTextAlignmentCenter;
        integralLab.layer.cornerRadius = 2;
        integralLab.layer.masksToBounds = YES;
        integralLab.backgroundColor = RGB(24, 159, 186);
        [whiteView addSubview:integralLab];
        CGRect bounds1 = [integralLab.text boundingRectWithSize:CGSizeMake(120*displaywidth, 15*displaywidth) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:NormalFontWithSize(11.0+fontScale)} context:nil];
        CGFloat width1 = bounds1.size.width+10;
        if (bounds1.size.width > 120*displaywidth)
        {
            width1 = 120*displaywidth;
        }
        integralLab.frame = CGRectMake(110*displaywidth, 65*displaywidth, width1, 15*displaywidth);
        
        UIView *lineview = [[UIView alloc] initWithFrame:CGRectMake(0, 90*displaywidth, SCREEN_WIDTH, 1*displaywidth)];
        lineview.backgroundColor = LinesColor;
        [whiteView addSubview:lineview];
        UIImageView *lastImgView = [ZCControl createImageViewWithFrame:CGRectMake(0, 96*displaywidth, 25*displaywidth, 30*displaywidth) ImageName:@"zuohua"];
        lastImgView.contentMode = UIViewContentModeScaleAspectFit;
        [whiteView addSubview:lastImgView];
        UIButton *lastBtn = [ZCControl createButtonWithFrame:CGRectMake(0, 91*displaywidth, 25*displaywidth, 40*displaywidth) ImageName:nil Target:self Action:@selector(lastAction) Title:nil Font:12.0];
        lastBtn.backgroundColor = [UIColor clearColor];
        [whiteView addSubview:lastBtn];
        
        UIImageView *nextImgView = [ZCControl createImageViewWithFrame:CGRectMake(SCREEN_WIDTH-25*displaywidth, 96*displaywidth, 25*displaywidth, 30*displaywidth) ImageName:@"youhua"];
        nextImgView.contentMode = UIViewContentModeScaleAspectFit;
        [whiteView addSubview:nextImgView];
        UIButton *nextBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-25*displaywidth, 91*displaywidth, 25*displaywidth, 25*displaywidth) ImageName:nil Target:self Action:@selector(nextAction) Title:nil Font:12.0];
        nextBtn.backgroundColor = [UIColor clearColor];
        [whiteView addSubview:nextBtn];
        titScrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(26*displaywidth, 91*displaywidth, SCREEN_WIDTH-52*displaywidth, 40*displaywidth)];
        titScrollview.backgroundColor = [UIColor whiteColor];
        titScrollview.delegate = self;
        titScrollview.contentOffset = CGPointMake(0, 0);
        titScrollview.pagingEnabled = NO;
        titScrollview.bounces = NO;
        titScrollview.showsHorizontalScrollIndicator = YES;
        [whiteView addSubview:titScrollview];
        if (goodsModel.productSizeList.count > 0)
        {
            CGFloat W = (SCREEN_WIDTH-52*displaywidth)/3;
            titScrollview.contentSize = CGSizeMake(W*goodsModel.productSizeList.count, 40*displaywidth);
            
            for (int i = 0; i < goodsModel.productSizeList.count; i++)
            {
                SizeListModel *sizeModel = goodsModel.productSizeList[i];
                NSString *typename = sizeModel.productSizeName;
                if (typename.length > 5)
                {
                    typename = [NSString stringWithFormat:@"%@...",[typename substringToIndex:5]];
                }
                UIButton *typeBtn = [ZCControl createButtonWithFrame:CGRectMake(W*i, 0, W, 39*displaywidth) ImageName:nil Target:self Action:@selector(closeTypeAction:) Title:typename Font:14.0];
                typeBtn.backgroundColor = [UIColor clearColor];
                [typeBtn setTitleColor:RGB(77, 77, 77) forState:UIControlStateNormal];
                if (i == 0)
                {
                    [typeBtn setTitleColor:ThemeColor forState:UIControlStateNormal];
                    
                }
                if (goodsModel.productSizeList.count == 1)
                {
                    typeBtn.frame = CGRectMake(W, 0, W, 39*displaywidth);
                }
                else if (goodsModel.productSizeList.count == 2)
                {
                    typeBtn.frame = CGRectMake((SCREEN_WIDTH-52*displaywidth)/4-W/2+(SCREEN_WIDTH-52*displaywidth)/2*i, 0, W, 39*displaywidth);
                }
                typeBtn.tag = 500+i;
                [titScrollview addSubview:typeBtn];
                JSBadgeView *badgeView = [[JSBadgeView alloc] initWithParentView:typeBtn alignment:JSBadgeViewAlignmentTopRight];
                badgeView.badgeText = @"";
                if ([_closeGoodsDic.allKeys containsObject:s_str(sizeModel.ID)])
                {
                    NSDictionary *numdic = [_closeGoodsDic objectForKey:s_str(sizeModel.ID)];
                    NSInteger zonnum = 0;
                    for (NSString *keystr in numdic)
                    {
                        NSString *numStr = [numdic objectForKey:keystr];
                        NSInteger numbers = [numStr integerValue];
                        zonnum += numbers;
                    }
                    badgeView.badgeText = s_Integer(zonnum);
                }
                badgeView.tag = 1000+i;
                [typeBtn addSubview:badgeView];
            }
            UIButton *btn = (UIButton *)[titScrollview viewWithTag:500];
            bottonLine = [[UIView alloc] initWithFrame:CGRectMake(btn.frame.origin.x+btn.frame.size.width/2-30*displaywidth, 39*displaywidth, 60*displaywidth, 1*displaywidth)];
            bottonLine.backgroundColor = ThemeColor;
            [titScrollview addSubview:bottonLine];
        }
        UIView *line33 = [[UIView alloc] initWithFrame:CGRectMake(0, 131*displaywidth, SCREEN_WIDTH, 4*displaywidth)];
        line33.backgroundColor = LinesColor;
        [whiteView addSubview:line33];
        if (goodsModel.productSizeList.count > 0)
        {
            SizeListModel *sizeModel22 = goodsModel.productSizeList[0];
            _typeGgAry = sizeModel22.productSizeDetailList;
        }
        self.ggTableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 135*displaywidth, SCREEN_WIDTH, 300*displaywidth) style:UITableViewStylePlain];
        _ggTableview.delegate = self;
        _ggTableview.dataSource = self;
        _ggTableview.tag = 22;
        _ggTableview.separatorStyle = UITableViewCellSeparatorStyleNone;
        _ggTableview.backgroundColor = BacksColor;
        [whiteView addSubview:_ggTableview];
//        tongjiLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 440*displaywidth, SCREEN_WIDTH-135*displaywidth, 35*displaywidth) Font:14.0 Text:@"共 0 件商品  合计：0.00" Color:RGB(77, 77, 77)];
//        tongjiLab.textAlignment = NSTextAlignmentRight;
//        NSMutableAttributedString *noteString = [[NSMutableAttributedString alloc] initWithString:tongjiLab.text];
//        NSRange stringRange = NSMakeRange(2, 1);
//        NSRange stringRange22 = NSMakeRange(tongjiLab.text.length-4, 4);
//        [noteString addAttribute:NSForegroundColorAttributeName value:RGB(241, 90, 36) range:stringRange];
//        [noteString addAttribute:NSForegroundColorAttributeName value:RGB(241, 90, 36) range:stringRange22];
//        [tongjiLab setAttributedText:noteString];
//        [whiteView addSubview:tongjiLab];
        tongjiLab = [ZCControl createLabelWithFrame:CGRectMake(10*displaywidth, 440*displaywidth, SCREEN_WIDTH-120*displaywidth, 35*displaywidth) Font:14.0 Text:@"共 0 件商品  合计：￥0.00元 + 0积分" Color:RGB(77, 77, 77)];
        tongjiLab.textAlignment = NSTextAlignmentRight;
        NSMutableAttributedString *noteString = [[NSMutableAttributedString alloc] initWithString:tongjiLab.text];
        NSRange stringRange = NSMakeRange(2, 1);
        NSRange stringRange22 = [[noteString string]rangeOfString:@"￥0.00"];
        NSRange stringRange33 = NSMakeRange(tongjiLab.text.length-3, 1);
        [noteString addAttribute:NSForegroundColorAttributeName value:RGB(241, 90, 36) range:stringRange];
        [noteString addAttribute:NSForegroundColorAttributeName value:RGB(241, 90, 36) range:stringRange22];
        [noteString addAttribute:NSForegroundColorAttributeName value:RGB(241, 90, 36) range:stringRange33];
        [tongjiLab setAttributedText:noteString];
        [whiteView addSubview:tongjiLab];
        UIButton *soureBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-100*displaywidth, 435*displaywidth, 100*displaywidth, 45*displaywidth) ImageName:nil Target:self Action:@selector(soureAction) Title:@"确定" Font:16.0];
        soureBtn.backgroundColor = ThemeColor;
        [soureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [whiteView addSubview:soureBtn];
    }
    _closeGgView.hidden = NO;
    [self changeNum];
}
//左移
- (void)lastAction
{
    CGFloat X = titScrollview.contentOffset.x+10;
    NSInteger index = X/((SCREEN_WIDTH-52*displaywidth)/3);
    if (index > 0)
    {
        CGFloat newX = (SCREEN_WIDTH-52*displaywidth)/3*(index-1);
        titScrollview.contentOffset = CGPointMake(newX, 0);
    }
    if (_indexrow != 0)
    {
        UIButton *btn = (UIButton *)[titScrollview viewWithTag:_indexrow+499];
        [self closeTypeAction:btn];
    }
}

//右移
- (void)nextAction
{
    CGFloat X = titScrollview.contentOffset.x+10;
    NSInteger index = X/((SCREEN_WIDTH-52*displaywidth)/3);
    if (_model.productSizeList.count > 3)
    {
        if (index < _model.productSizeList.count-3)
        {
            CGFloat newX = (SCREEN_WIDTH-52*displaywidth)/3*(index+1);
            titScrollview.contentOffset = CGPointMake(newX, 0);
        }
    }
    
    if (_indexrow != _model.productSizeList.count-1)
    {
        UIButton *btn = (UIButton *)[titScrollview viewWithTag:_indexrow+501];
        [self closeTypeAction:btn];
    }
    
}

- (void)closeTypeAction:(UIButton *)btn
{
    NSInteger index = btn.tag-500;
    _indexrow = index;
    for (id v in titScrollview.subviews)
    {
        if ([v isKindOfClass:[UIButton class]])
        {
            UIButton *button = (UIButton *)v;
            [button setTitleColor:RGB(77, 77, 77) forState:UIControlStateNormal];
            
        }
    }
    [btn setTitleColor:ThemeColor forState:UIControlStateNormal];
    bottonLine.frame = CGRectMake(btn.frame.origin.x+btn.frame.size.width/2-30*displaywidth, 39*displaywidth, 60*displaywidth, 1*displaywidth);
    SizeListModel *sizeModel = _model.productSizeList[index];
    _typeGgAry = sizeModel.productSizeDetailList;
    [_ggTableview reloadData];
    
}

//减少数量
- (void)deleteBtnAction:(UIButton *)btn
{
    NSInteger index = btn.tag-200;
    SizeDetailModel *model = _typeGgAry[index];
    if ([_closeGoodsDic.allKeys containsObject:model.productSizeId])
    {
        NSDictionary *dic = [_closeGoodsDic objectForKey:model.productSizeId];
        NSMutableDictionary *newDic = [NSMutableDictionary dictionaryWithCapacity:0];
        [newDic addEntriesFromDictionary:dic];
        if ([dic.allKeys containsObject:model.ID])
        {
            NSString *numStr = [dic objectForKey:model.ID];
            NSInteger num = [numStr integerValue];
            if (num > 0)
            {
                num--;
            }
            [newDic setObject:[NSString stringWithFormat:@"%ld",num] forKey:model.ID];
        }
        else
        {
            [newDic setObject:@"0" forKey:model.ID];
        }
        [_closeGoodsDic setObject:newDic forKey:model.productSizeId];
    }
    else
    {
        return;
    }
    [_ggTableview reloadData];
    [self changeNum];
    
}

//添加数量
- (void)addBtnAction:(UIButton *)btn
{
    NSInteger index = btn.tag-2200;
    SizeDetailModel *model = _typeGgAry[index];
    if ([_closeGoodsDic.allKeys containsObject:model.productSizeId])
    {
        NSDictionary *dic = [_closeGoodsDic objectForKey:model.productSizeId];
        NSMutableDictionary *newDic = [NSMutableDictionary dictionaryWithCapacity:0];
        [newDic addEntriesFromDictionary:dic];
        if ([dic.allKeys containsObject:model.ID])
        {
            NSString *numStr = [dic objectForKey:model.ID];
            NSInteger num = [numStr integerValue]+1;
            [newDic setObject:[NSString stringWithFormat:@"%ld",num] forKey:model.ID];
        }
        else
        {
            [newDic setObject:@"1" forKey:model.ID];
        }
        [_closeGoodsDic setObject:newDic forKey:model.productSizeId];
    }
    else
    {
        NSMutableDictionary *newDic = [NSMutableDictionary dictionaryWithCapacity:0];
        [newDic setObject:@"1" forKey:model.ID];
        [_closeGoodsDic setObject:newDic forKey:model.productSizeId];
        
    }
    [_ggTableview reloadData];
    [self changeNum];
}

- (void)changeNum
{
    UIButton *btn = (UIButton *)[titScrollview viewWithTag:_indexrow+500];
    JSBadgeView *jsview = (JSBadgeView *)[btn viewWithTag:_indexrow+1000];
    SizeListModel *sizeModel = _model.productSizeList[_indexrow];
    if ([_closeGoodsDic.allKeys containsObject:sizeModel.ID])
    {
        NSDictionary *dic = [_closeGoodsDic objectForKey:sizeModel.ID];
        NSInteger zongNum = 0;
        for (NSString *key in dic)
        {
            NSString *numStr = [dic objectForKey:key];
            NSInteger num = [numStr integerValue];
            zongNum += num;
        }
        if (zongNum == 0)
        {
            jsview.badgeText = @"";
            
        }
        else
        {
            jsview.badgeText = [NSString stringWithFormat:@"%ld",zongNum];
        }
        
    }
    else
    {
        jsview.badgeText = @"";
    }
    [self tongjiNumberAndMoney];
    
}

- (void)tongjiNewNumberAndMoney
{
    NSInteger zongNum = [numTextfield.text integerValue];
    NSArray *producListAry = _model.productSizeList;
    SizeListModel *sizeModel = producListAry[_classType];
    NSArray *SizeDetailAry = sizeModel.productSizeDetailList;
    SizeDetailModel *detailmodel = SizeDetailAry[_speciType];
    _csID = s_str(detailmodel.ID);
    CGFloat price = [detailmodel.price floatValue];
    CGFloat zongPrice = price*zongNum;
    CGFloat integral = [detailmodel.integral floatValue];
    CGFloat zongIntegral = integral*zongNum;
    _allNumber = zongNum;
    
    tongjiLab.text = [NSString stringWithFormat:@"共 %ld 件商品  合计: ￥%.2lf元 + %.0lf积分",zongNum,zongPrice,zongIntegral];
    NSString *zonNumStr = [NSString stringWithFormat:@"%ld",zongNum];
    NSMutableAttributedString *noteString = [[NSMutableAttributedString alloc] initWithString:tongjiLab.text];
    NSRange titleRange = [[noteString string]rangeOfString:[NSString stringWithFormat:@" %.0lf",zongIntegral]];
    NSRange stringRange = NSMakeRange(2, zonNumStr.length);
    NSRange stringRange22 = [[noteString string]rangeOfString:[NSString stringWithFormat:@" ￥%.2lf",zongPrice]];
    [noteString addAttribute:NSForegroundColorAttributeName value:RGB(241, 90, 36) range:titleRange];
    [noteString addAttribute:NSForegroundColorAttributeName value:RGB(241, 90, 36) range:stringRange];
    [noteString addAttribute:NSForegroundColorAttributeName value:RGB(241, 90, 36) range:stringRange22];
    [tongjiLab setAttributedText:noteString];
    
    [_closeGoodsDic removeAllObjects];
    if (zongPrice > 0)
    {
        pricelab.text = [NSString stringWithFormat:@"￥%.2lf元 +",price];
        integralLab.text = [NSString stringWithFormat:@"%@积分",detailmodel.integral];
        NSMutableDictionary *newDic = [NSMutableDictionary dictionaryWithCapacity:0];
        [newDic setObject:s_Integer(zongNum) forKey:detailmodel.ID];
        [_closeGoodsDic setObject:newDic forKey:detailmodel.productSizeId];
    }
    else
    {
        pricelab.text = [_model.priceDescribe stringByAppendingString:@" +"];
        integralLab.text = [NSString stringWithFormat:@"%@积分",_model.integral];
    }
    CGRect bounds1 = [integralLab.text boundingRectWithSize:CGSizeMake(120*displaywidth, 15*displaywidth) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:NormalFontWithSize(11.0+fontScale)} context:nil];
    CGFloat width1 = bounds1.size.width+10;
    if (bounds1.size.width > 120*displaywidth)
    {
        width1 = 120*displaywidth;
    }
    integralLab.frame = CGRectMake(100*displaywidth, 70*displaywidth, width1, 15*displaywidth);
}


- (void)tongjiNumberAndMoney
{
    NSInteger zongNum = 0;
    CGFloat zongPrice = 0;
    CGFloat zongIntegral = 0;
    for (NSString *key in _closeGoodsDic)
    {
        NSDictionary *typeDic = [_closeGoodsDic objectForKey:key];
        NSDictionary *typePriceDic = [_priceDic objectForKey:key];
        NSDictionary *integralDic = [_integDic objectForKey:key];

        for (NSString *key22 in typeDic)
        {
            NSString *numStr = [typeDic objectForKey:key22];
            NSString *djprice = [typePriceDic objectForKey:key22];
            NSString *integStr = [integralDic objectForKey:key22];
            NSInteger num = [numStr integerValue];
            CGFloat thePrice = [djprice floatValue];
            CGFloat money = thePrice*num;
            zongNum += num;
            zongPrice += money;
            CGFloat integ = [integStr floatValue]*num;
            zongIntegral += integ;
            
        }
    }
    _allNumber = zongNum;
    tongjiLab.text = [NSString stringWithFormat:@"共 %ld 件商品  合计: ￥%.2lf元 + %.0lf积分",zongNum,zongPrice,zongIntegral];
    NSString *zonNumStr = [NSString stringWithFormat:@"%ld",zongNum];
    NSMutableAttributedString *noteString = [[NSMutableAttributedString alloc] initWithString:tongjiLab.text];
    NSRange titleRange = [[noteString string]rangeOfString:[NSString stringWithFormat:@" %.0lf",zongIntegral]];
    NSRange stringRange = NSMakeRange(2, zonNumStr.length);
    NSRange stringRange22 = [[noteString string]rangeOfString:[NSString stringWithFormat:@" ￥%.2lf",zongPrice]];
    [noteString addAttribute:NSForegroundColorAttributeName value:RGB(241, 90, 36) range:titleRange];
    [noteString addAttribute:NSForegroundColorAttributeName value:RGB(241, 90, 36) range:stringRange];
    [noteString addAttribute:NSForegroundColorAttributeName value:RGB(241, 90, 36) range:stringRange22];
    [tongjiLab setAttributedText:noteString];
    
}


- (void)getAllGgPrice
{
    NSArray *typeAry = _model.productSizeList;
    for (SizeListModel *model in typeAry)
    {
        NSArray *ggAry = model.productSizeDetailList;
        NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:0];
        NSMutableDictionary *dic22 = [NSMutableDictionary dictionaryWithCapacity:0];
        for (SizeDetailModel *detaModel in ggAry)
        {
            [dic setObject:detaModel.price forKey:detaModel.ID];
            [dic22 setObject:detaModel.integral forKey:detaModel.ID];
        }
        [_priceDic setObject:dic forKey:model.ID];
        [_integDic setObject:dic forKey:model.ID];
        
    }
}
//确认规格
- (void)soureAction
{
    [self requestAddShoppingCart];
}

//重选规格
- (void)requestAddShoppingCart
{
    WEAKSELF;
    NSMutableArray *theGgAry = [NSMutableArray arrayWithCapacity:0];
    for (NSString *key in _closeGoodsDic)
    {
        NSDictionary *typeDic = [_closeGoodsDic objectForKey:key];
        for (NSString *key22 in typeDic)
        {
            NSString *numStr = [typeDic objectForKey:key22];
            if ([numStr integerValue] > 0)
            {
                NSDictionary *ggdic = @{@"productSizeDetailId":key22,
                                        @"num":numStr
                                        };
                [theGgAry addObject:ggdic];
            }
        }
    }
    if (theGgAry.count == 0)
    {
        [LTools showMBProgressWithText:@"请选择规格" addToView:self.view];
        return;
    }
    NSDictionary *dic = @{@"id":_ordModel.ID,
                          @"productId":_model.ID,
                          @"shoppingCartDetailList":theGgAry
                          };
    [HYBaseHandler requestAddShoppingCartParmers:dic Success:^(id obj)
     {
         if ([obj server_Getcodecheck])
         {
             [weakSelf backGGAction];
             weakSelf.page = 0;
             [weakSelf requestShoppingCartList];
         }
         else
         {
             [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
         }
     } failed:^(NSError *error) {
         
     }];
}

//购物车列表
- (void)requestShoppingCartList
{
    WEAKSELF;
    [self getSelectedArray];
    NSDictionary *dic = @{@"page":[NSString stringWithFormat:@"%ld",_page]};
    [HYBaseHandler requestShoppingCartListParmers:dic Success:^(id obj)
    {
        if ([obj server_Getcodecheck])
        {
            dispatch_async(dispatch_get_main_queue(), ^{
                if (_page == 0)
                {
                    [weakSelf.shopAry removeAllObjects];
                }
                NSArray *orderAry = [OrderModel mj_objectArrayWithKeyValuesArray:obj[@"data"][@"content"]];
                [weakSelf.shopAry addObjectsFromArray:orderAry];
                if (weakSelf.selectArray.count > 0 && weakSelf.shopAry.count > 0)
                {
                    for (OrderModel *model in weakSelf.shopAry)
                    {
                        if ([weakSelf.selectArray containsObject:model.ID])
                        {
                            model.isXuanZh = YES;
                        }
                    }
                }
                [weakSelf.tableview reloadData];
                if (weakSelf.shopAry.count == 0)
                {
                    weakSelf.emptyImgview.hidden = NO;
                    weakSelf.tostLabel.hidden = NO;
                    
                }
                else
                {
                    
                    weakSelf.emptyImgview.hidden = YES;
                    weakSelf.tostLabel.hidden = YES;
                }
                [weakSelf getSelectedArray];
            });
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
        [weakSelf.tableview.mj_header endRefreshing];
        [weakSelf.tableview.mj_footer endRefreshing];
    } failed:^(NSError *error) {
        [weakSelf.tableview.mj_header endRefreshing];
        [weakSelf.tableview.mj_footer endRefreshing];
    }];
}

//删除商品
- (void)requestShoppingCartDelete
{
    NSString *idStr = [_selectArray componentsJoinedByString:@","];
    NSDictionary *dic = @{@"ids":idStr};
    WEAKSELF;
    [HYBaseHandler requestShoppingCartDeleteParmers:dic Success:^(id obj)
    {
        if ([obj server_Getcodecheck])
        {
            [LTools showMBProgressWithText:@"删除成功" addToView:self.view];
            weakSelf.page = 0;
            [weakSelf loadNewHeaderData];
            [weakSelf allCloseAction:weakSelf.allCloseBtn];
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {
        
    }];
}


- (void)getSelectedArray
{
    [_selectArray removeAllObjects];
    [_selectOrderArray removeAllObjects];
    CGFloat zongPrice = 0;
    CGFloat zonginteg = 0;

    for (OrderModel *model in _shopAry)
    {
        if (model.isXuanZh)
        {
            [_selectArray addObject:model.ID];
            [_selectOrderArray addObject:model];
            CGFloat price = [model.moneyTol floatValue];
            CGFloat integ = [model.integralTol floatValue];
            zongPrice += price;
            zonginteg += integ;
        }
    }
    _totalPriceLab.text = [NSString stringWithFormat:@"合计：￥%.2lf元 + %.0f积分",zongPrice,zonginteg];
}

- (void)backGGAction
{
    _closeGgView.hidden = YES;
}

-(void)viewTapped:(UITapGestureRecognizer*)tap1
{
    [_closeGgView endEditing:YES];
    [self.view endEditing:YES];
}
- (void)jianpanhuishou:(NSNotification *)notification
{
    _closeGgView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    _closeGgView.frame = CGRectMake(0, -220*displaywidth, SCREEN_WIDTH, SCREEN_HEIGHT+220*displaywidth);
    if ([textField.text isEqualToString:@"0"])
    {
        textField.text = @"";
    }
    
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if (textField == numTextfield && _isClose)
    {
        [self tongjiNumberAndMoney];
    }
    else
    {
        NSInteger index = textField.tag-3000;
        SizeDetailModel *model = _typeGgAry[index];
        if ([_closeGoodsDic.allKeys containsObject:model.productSizeId])
        {
            NSDictionary *dic = [_closeGoodsDic objectForKey:model.productSizeId];
            NSMutableDictionary *newDic = [NSMutableDictionary dictionaryWithCapacity:0];
            [newDic addEntriesFromDictionary:dic];
            [newDic setObject:textField.text forKey:model.ID];
            [_closeGoodsDic setObject:newDic forKey:model.productSizeId];
        }
        else
        {
            NSMutableDictionary *newDic = [NSMutableDictionary dictionaryWithCapacity:0];
            [newDic setObject:textField.text forKey:model.ID];
            [_closeGoodsDic setObject:newDic forKey:model.productSizeId];
            
        }
        [self changeNum];
    }
}

-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
    [_closeGgView endEditing:YES];
    [self.view endEditing:YES];
    return indexPath;
}
// 滑动的时候 searchBar 回收键盘

- (void)scrollViewWillBeginDragging:(UIScrollView*)scrollView
{
    [_closeGgView endEditing:YES];
    [self.view endEditing:YES];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [_closeGgView endEditing:YES];
    [self.view endEditing:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
